Repository navigation
grid3d 0.5.3: hardening, a slow 3D view goes back to 2D, and a 2D/3D switch that reads as a choice - #84
Merged
Conversation
…lank page Strata 0.9.0's grid-relay.js forgets a close() that arrives while its module loads: it finishes "ready" on a hidden canvas, and a later request() returns at once without showing it, so the template hid the 2D canvas with nothing in its place. The template now closes and reopens a relay found ready on a hidden canvas, stops a relay that finishes loading after 2D was chosen, and counts the 3D view as drawing only when its canvas is shown. A Node test drives the template's script against a stand-in for the 0.9.0 relay. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…made the mistake Counts over the relay's limits, non-finite numbers, coordinates past 1e6, lights with no radius or a negative colour or intensity, HUD colours out of range and a camera whose eye is on its target now raise WireError with the relay's status. A lone surrogate in a label is sent as "?" and a NUL is dropped on both backends; measureText no longer counts NULs. golden/wire-1.0.hex pins one message of each kind, and edge-case tests cover picking, board edges, viewports and the Animator. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…a raises a ValueError that says so Before, such a camera failed with ZeroDivisionError deep in cameraBasis. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
beginFrame and endFrame no longer raise AttributeError, drawImage is recorded (RecordedImage, exported next to 0.5.2's touch-key names), and getVersion and the colour constants are there. A test compares the recorder with Graphik's public names. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…t it fetches A refused tarball no longer leaves files behind, a linked folder in --dest cannot carry a file out, the relay folder is capped at 64 MB, --strata takes only a release version, SHA256SUMS lines that disagree or are not SHA-256 are refused, and --replace updates an earlier relay's files (never index.html). drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
The job installs the strata extra and Mesa and runs the grid3d tests with GRAPHIK_REQUIRE_STRATA=1, so the golden-image and mid-tick render tests run on every pull request instead of skipping. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
Every public class and function is listed, grouped by area, with an example for each group; 0.5.2's portrait framing (fitCamera top and bottom, setInsets), touchScreen() and the touch keys are covered in a Touch keys section. The README and the package docstring link to it. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
The relay's onSlow calls StrataLoader.slow(), which does nothing on graphik's page, and the template's "slow" reason was never used. The page now watches the drawing itself once Strata's kit is at its lowest quality tier and pixel density 1: second by second, the typical frame (the median gap between the page's requestAnimationFrame calls, long stalls cut), the relay's own drawing a frame (its stats' cpuMs) and the kit's own average frame (frameMs). When for 5 seconds the typical frame and the kit's average are over 66 ms and the drawing is at least a quarter of the typical frame, the page goes back to 2D and the note says "Back to 2D: this device draws the 3D view too slowly. Press 3D to try it again." A game that stops the page now and then (building and sending a board in Python), or that is slow every frame while the drawing is cheap, stays in 3D: 2D would not help it. Counting starts 3 seconds after the game's first message to the 3D view (pygbag's boot and the first shader compile are not counted) and stops while the tab is hidden. The switch is not remembered as the player's choice and is not a failure: the button still offers 3D, and once the player chooses 3D again the page leaves it alone until it is reloaded. ?slow=0 in the address turns the switch off (for testing on a machine that draws in software); Graphik3D.slowed() says it happened and Graphik3D.speed() gives the last second's readings. Node tests drive it against a stand-in relay and page frames: slow drawing switches (stalls or not); a stalling game with fast drawing, a slow game with cheap drawing, and a kit reporting fast frames (as browser test harnesses pin it on software GL) don't. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
The button read "2D" while the 3D view was on, like a status. It is now a
switch with both views on it, 2D and 3D, the current one highlighted; to
a screen reader it is a toggle named "3D view", aria-pressed while 3D is
on ("3D view unavailable" when 3D cannot start), and data-view says what
is on show. It is at least 44 CSS pixels each way (it was 36 tall), the
note sits below it, and buttonArea() measures it as drawn. A duplicated
comment opener in the template was removed.
drafted by Claude on behalf of Daniel Stephenson
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…oard the relay has On a 64 x 64 board most of a desktop frame's Python went into building one RenderItem object per shape. Grid3DView.drawScene now packs a scene's shapes into a ctypes array of RenderItems in one pass (view.py renderItems(); submit_primitives takes it without a copy), byte for byte what the objects gave, about twelve times faster; a 3-part colour or a binding whose RenderItem is not the 44-byte structure goes the old way. The web backend encodes a BOARD's shapes in one pass too, with the relay's checks made on all the values at once (any failure goes through the shape-by-shape path for its message), and Grid3DWebView.setBoard no longer sends a BOARD identical to the last one, so the relay doesn't rebuild an unchanged board. Games build a fresh Scene every frame, so the shapes are packed fast rather than cached. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
The version and the README's install lines say 0.5.3: the grid3d hardening, the slow fallback to 2D and the 2D/3D switch. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This builds on 0.5.2 (portrait framing and touch keys) and is released as 0.5.3. It has eleven commits: the grid3d hardening (01-07), two changes to the page template (08-09), a cut in the Python cost of a frame (10) and the version bump (11).
Hardening (01-07)
templates/pygbag.tmpl). Strata 0.9.0'sgrid-relay.jsforgets aclose()that arrives while its module loads: it finishesreadyon a hidden canvas, and a laterrequest()returns at once without showing it. The template now closes and reopens a relay it findsreadyon a hidden canvas, stops a relay that finishes loading after 2D was chosen, and counts the 3D view as drawing only when its canvas is shown. A Node test drives the template's script against a stand-in for the 0.9.0 relay.web.py,WireError), with the relay's status, where the game made the mistake: counts over the limits, non-finite numbers, coordinates past ±10⁶, bad lights, bad HUD colours, and a camera whose eye is on its target. Label text: a lone surrogate is sent as?and a NUL is dropped on both backends.golden/wire-1.0.hexpins one message of each kind.ValueErrorthat says so (it used to be aZeroDivisionError).ScreenRecorderanswers every public call and constant thatGraphikhas (beginFrame/endFrame,drawImage→RecordedImage,getVersion, the colours). A test compares the two, so a newGraphikmethod can't be missed.relay.pychecks every tarball member before it writes anything, refuses a link that leads out of--dest, caps the relay at 64 MB, accepts only a release version in--strata, refuses badSHA256SUMSlines, and makes--replaceupdate an earlier relay's files (neverindex.html).grid3d render (Strata, llvmpipe)job runs the grid3d tests withGRAPHIK_REQUIRE_STRATA=1, so the golden-image and mid-tick render tests run on every PR instead of being skipped.docs/grid3d.md: an API reference for every public name, with an example for each area. It also covers 0.5.2's names:fitCamera(top, bottom),setInsets,touchScreen(), and a Touch keys section.When the hardening was put on top of 0.5.2,
__init__.pywas the only conflict, in two places:RecordedImagewas added to__all__alongside 0.5.2's touch-key names, and the docstring's pointer todocs/grid3d.mdwas moved after 0.5.2'stouchkeys.pysentence. The template,test_grid3d_web.pyand the README merged without conflicts, and both behaviours stay in place:touch()andarea()sit beside the relay workaround.A 3D view whose drawing stays too slow goes back to 2D (08)
Strata's kit handles slow frames itself. It first lowers its pixel density to 1, then its quality tier. When it has nothing left to give up, it calls
onSlow, and the relay passes that toStrataLoader.slow(), which does nothing on graphik's page. The template's"slow"reason was never used.The page now watches the drawing itself once the kit is at quality 0 and pixel density 1. Every second it takes three readings:
requestAnimationFramecalls, with stalls far past the median cut;cpuMsfrom itsstats(), reset each second;frameMsfrom the samestats().When for 5 seconds the typical frame and the kit's average are both over 66 ms, and the drawing is at least a quarter of the typical frame, the page goes back to 2D. The note says: "Back to 2D: this device draws the 3D view too slowly. Press 3D to try it again."
localStorage, and the button still offers 3D. Once the player chooses 3D again, the page leaves 3D on, however slow, until a reload.?slow=0in the address turns the switch off, for testing on a machine that draws in software.Graphik3D.slowed()returns 1 once the switch has happened, andGraphik3D.speed()gives the last second's readings.frameMsto keep 3D on in software GL. On that machine Apex's relay really does draw a 29 x 29 board in 46-330 ms a frame;speed()showed typical frames of 50-480 ms. An intermediate build that read only the page's frames andcpuMsignored that pin. The game then rightly closed its 3D view, its Python 3D frames dropped to 0-2 a run, and keys aimed at the 3D HUD stopped showing. With all three readings required, the pin is honoured again, and a Node test covers it.The 2D/3D button reads as a choice (09)
While 3D was on, the button read "2D", which looked like a status. It is now a switch showing both views, 2D and 3D, with the current one highlighted.
aria-pressedset while 3D is on. When 3D can't start, it reads "3D view unavailable" andaria-disabledis set.buttonArea()measures it as drawn.data-viewgives what is on show (2d,3dorunavailable).A duplicated comment opener in the template was also removed.
Frame cost in Python (10)
On a 64 x 64 board, most of a desktop frame's Python time went into building one
RenderItemobject per shape. The games build a freshSceneevery frame, so caching the board's items wouldn't help them; packing the shapes fast does:Grid3DView.drawScenepacks a scene's shapes into a ctypes array ofRenderItems in one pass (view.renderItems();submit_primitivestakes the array without a copy). The bytes are identical to building the objects one by one. A 3-part colour, or a binding whoseRenderItemisn't the 44-byte structure, goes the old way.BOARD's shapes in one pass, with the relay's checks made on all the values at once. On any failure it falls back to the shape-by-shape path, which raises the precise error.Grid3DWebView.setBoardno longer resends aBOARDidentical to the last one, so the relay doesn't rebuild an unchanged board.Python time per call, median of 30, measured on an Apex-like board (Linux, Python 3.12; engine calls stubbed out so the GPU isn't counted; [before → after]):
drawScenedrawScene, board unchangedsetBoard, board unchanged: bytes sentThe game's own scene building (a fresh
GridBoardandboard.scene(), about 19 ms at 64 x 64) is unchanged, and so is the websetBoardtime, which is mostly the board's shapes (about 20 ms at 64 x 64). These numbers are from a busy shared machine, so treat them as ratios.Tests
python -m pytest: 493 passed. WithGRAPHIK_REQUIRE_STRATA=1(Strata 0.8.0 on llvmpipe): 493 passed, none skipped. The suite was also run on the tree after each commit: 07 (471), 08 (481), 09 (484), 10 (493), 11 (493).Node template tests (
test_grid3d_template_js.py), 15 in all:?slow=0turns the switch off;test_grid3d_frame_cost.py(9 tests):RenderItems byte for byte, against a stand-in 44-byte structure and the real binding;BOARDbyte for byte, and refusing NaN, infinity and out-of-range values as before;setBoardwith an unchanged board sends noBOARD, but still sendsVIEWandPIECES.The three games' browser e2e, built with this tree on Strata 0.9.0's relay:
Ophidian's phone e2e, run on Strata 0.9.0's relay and again with 0.9.1's integrated
grid-relay.js,strata-kit.jsandstrata-loader.jscopied over 0.9.0's (390 x 844, touch), 78/79 on each. It covers:aria-pressed=true;?view=2d; the engine or relay script blocked, which shows "3D unavailable";The one failure is a check written for an older Ophidian 2D layout; the game's own harness passes it.
The slow switch in the browser (
e2e-slow.cjs, a DPR-1 phone), on both relays, 8/8 each:Startup: on 0.9.1, the relay starts its frame loop on the first accepted message. The page's own slow check only starts 3 s after that message. No startup penalty from graphik was seen; in both runs the kit was already at q0 by the first reading, on software GL.
drafted by Claude on behalf of Daniel Stephenson
🤖 Generated with Claude Code